#include "Bone.h"
#include "Tools.h"
#include <tinyxml.h>

Bone::Bone()
{
	mParent = NULL;
}

Bone::Bone(const Bone&)
{

}

Bone::~Bone()
{

}

void Bone::Initialize(TiXmlElement* boneElement)
{
	mName = std::string(boneElement->Attribute("name"));
	
	const char *strParentName = boneElement->Attribute("parentBone");
	if(strParentName != NULL)
	{
		mParentBoneName = std::string(strParentName);
	}
	else
	{
		mParentBoneName = std::string("");
	}

	const char *strMain = boneElement->Attribute("main");
	if(strMain != NULL)
	{
		mMain = true;
	}
	else
	{
		mMain = false;
	}
	
}

Bone* Bone::GetParent()
{
	return mParent;
}

std::string Bone::GetName()
{
	return mName;
}

std::string Bone::GetParentName()
{
	return mParentBoneName;
}

void Bone::SetParent(Bone* pParent)
{
	mParent = pParent;
	mParent->AddSubBone(this);
}

bool Bone::IsMain()
{
	return mMain;
}

void Bone::AddSubBone(Bone* pBone)
{
	mSubBones.push_back(pBone);
}

void Bone::SetMeshIndex(int pIndex)
{
	mMeshIndex = pIndex;
}

int Bone::GetMeshIndex()
{
	return mMeshIndex;
}

std::vector<Bone*>::iterator Bone::GetSubBonesBegin()
{
	return mSubBones.begin();
}

std::vector<Bone*>::iterator Bone::GetSubBonesEnd()
{
	return mSubBones.end();
}